<?php
class EWebby_UI_Page extends EWebby_UI_Widgets_Widget
	implements EWebby_IHttpHandler {
	public static $formatOutput = false;
	public static $preserveWhiteSpace = false;
		
	public $isPagePostBack = false;
	public $isPageCallBack = false;
	public $allowBrowserCache = true;

	public function __construct() {
		parent::__construct();
		
		$this->isPagePostBack = ( strtolower($_SERVER ['REQUEST_METHOD']) == 'post' );
		$this->isPageCallBack = ( isset($_POST [self::CALLBACKIDENTITY]) );
	}
	
	public function getTitle() {
		$nodes = $this->queryDocument('//title');
		if( count($nodes) > 0 ) {
			return $nodes[0]->nodeValue;
		}
		
		return '';
	}	
	public function setTitle($text) {
		$nodes = $this->queryDocument('//title');
		if( count($nodes) > 0 ) {
			$nodes[0]->nodeValue = $text;
		}
	}

	public final function process($application) {
		$this->init();
		
		if( !$this->allowBrowserCache ) {
			header('Cache-Control: no-store, no-cache, must-revalidate');
			header('Cache-Control: post-check=0, pre-check=0');
			header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
			header('Date: ' . gmdate('D, d M Y H:i:s') . ' GMT' );
			header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT' );
			header('Pragma: no-cache');
		}
		
		$this->load();
		$this->preRender();

		// render the page
		echo( (self::$_callBackElement != null)?
			self::$_callBackElement->render() :	// at javascript callback
			$this->render()
		);

		$this->unload();
	}
}